package com.iflysse.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.iflysse.interceptor.TokenInterceptor;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
	
	@Value("${web.upload-path}")
	 private String path;
	
	@Value("${web.upload-new-path}")
	 private String newPath;
	
	@Autowired
	private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/","/user/login","/user/code","/user/retrievePassword",
                        "/user/resetPassword",newPath+"**",newPath+"images/cover/**")
                .excludePathPatterns("/webjars/**")
    			.excludePathPatterns("/swagger-resources/**")
    			.excludePathPatterns("/doc.html")
    			.excludePathPatterns("/swagger-ui.html");
    }
    
    /**
     * 虚拟路径配置
     * @param registry
     */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler(newPath+"**").addResourceLocations("file:"+path);
		registry.addResourceHandler(newPath+"images/cover/**").addResourceLocations("file:"+path);
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}


}
